/** 
 * Project Name:kaka 
 * File Name:HomeAction.java 
 * Package Name:com.luoran.kaka.api.wechat 
 * Date:2018年12月19日下午4:05:07 
 * Copyright (c) 2018, Luoran, Inc. All Rights Reserved.
 * 
 */  
package com.luoran.kaka.api.wechat;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.luoran.kaka.api.wechat.model.CardInfoVo;
import com.luoran.kaka.service.IHomeService;

/** 
 * @author ghl 
 * @since JDK 1.8
 * ClassName: HomeAction
 * date: 2018年12月19日 下午4:05:07
 *	
 */
@Controller
@RequestMapping("/api/home")
public class HomeAction {
	
	private static final Logger log = LoggerFactory.getLogger(HomeAction.class);
	
	@Autowired
	private IHomeService homeService;

	
	/** 
	 * @return 
	 * @since JDK 1.8
	 * @author ghl  by 2018年12月19日下午4:24:16
	 * showHome:小程序首页.默认加载数据
	 */ 
	@RequestMapping("/query")
	@ResponseBody
	public JSONObject showHome(@RequestParam(name="condition",required=false)String condition) {
		JSONObject obj = new  JSONObject();
		log.info("[当前查询条件为:]{}",condition);
		try {
			List<CardInfoVo> list = homeService.queryAllPublicCard(condition);
			if (list!=null&&list.size()>0) {
				obj.put("flag", true);
				obj.put("list", list);
			}else {
				obj.put("flag", false);
				obj.put("code", 200);
				obj.put("msg", "暂无更多数据！");
			}
		} catch (Exception e) {
			log.error(e.getMessage(),e.fillInStackTrace());
			obj.put("flag", false);
			obj.put("code", 500);
			obj.put("msg", "网络异常");
		}
		return obj;
	}

}
